const path = require('path')
const inquirer = require('inquirer')

const { VUE_VERSION } = require('../constants/index')
const { generator } = require('../utils/generator')
/**
 * 创建工程
 */
module.exports = async function (type) {
  const programNameList = [
    {
      type: 'input',
      name: 'projectName',
      message: '请输入项目名称',
    },
  ]
  const programVueVersion = [
    {
      type: 'list',
      name: 'vueVersion',
      message: '请选择vue版本',
      choices: VUE_VERSION.map(item => item.version),
    },
  ]
  let TEMPLATE_DIR
  inquirer.prompt(programNameList).then(optionS1 => {
    if (!optionS1.projectName) {
      return
    }
    inquirer.prompt(programVueVersion).then(optionS2 => {
      if (optionS2.vueVersion === 'vue3') {
        TEMPLATE_DIR = path.join(__dirname, `../../template_vue3_${type}`)
        generator({ ...optionS1, ...optionS2 }, TEMPLATE_DIR)
      } else {
        TEMPLATE_DIR = path.join(__dirname, `../../template_vue2_${type}`)
        generator({ ...optionS1, ...optionS2 }, TEMPLATE_DIR)
      }
    })
  })
}
